sep.d <- read.table('makespan_sep.txt', header=TRUE)

sep.df <- reshape(sep.d, v.names="MAKESPAN", idvar=c("TASK","DEMANDA","ESCALONADOR","CHECK","DENSIDADE"), timevar="GREEN", direction="wide")

sep.df$SLOWDOWN.SLEEP <- sep.df$MAKESPAN.SLEEP / sep.df$MAKESPAN.OFF
sep.df$SLOWDOWN.STANDBY <- sep.df$MAKESPAN.STANDBY / sep.df$MAKESPAN.OFF

stats <- aggregate(sep.df$SLOWDOWN.SLEEP, list(sep.df$DENSIDADE,sep.df$ESCALONADOR,sep.df$CHECK), mean)

colnames(stats) <- c("DENSIDADE","ESCALONADOR","CHECK","MEAN_SLOWDOWN.SLEEP")

stats$MEAN_SLOWDOWN.STANDBY <- aggregate(sep.df$SLOWDOWN.STANDBY, list(sep.df$DENSIDADE,sep.df$ESCALONADOR,sep.df$CHECK), mean)$x

stats$MEAN_RUNTIME <- aggregate(sep.df$RUNTIME, list(sep.df$DENSIDADE,sep.df$ESCALONADOR,sep.df$CHECK), mean)$x

stats$N <- aggregate(sep.df$TASK, list(sep.df$DENSIDADE,sep.df$ESCALONADOR,sep.df$CHECK), length)$x

stats$SD_SLOWDOWN.SLEEP <- aggregate(sep.df$SLOWDOWN.SLEEP, list(sep.df$DENSIDADE,sep.df$ESCALONADOR,sep.df$CHECK), sd)$x

stats$SD_SLOWDOWN.STANDBY <- aggregate(sep.df$SLOWDOWN.STANDBY, list(sep.df$DENSIDADE,sep.df$ESCALONADOR,sep.df$CHECK), sd)$x

stats$UPPER_SLOWDOWN.SLEEP <- stats$MEAN_SLOWDOWN.SLEEP + qnorm(0.975)*stats$SD_SLOWDOWN.SLEEP/sqrt(stats$N)

stats$LOWER_SLOWDOWN.SLEEP <- stats$MEAN_SLOWDOWN.SLEEP - qnorm(0.975)*stats$SD_SLOWDOWN.SLEEP/sqrt(stats$N)

stats$UPPER_SLOWDOWN.STANDBY <- stats$MEAN_SLOWDOWN.STANDBY + qnorm(0.975)*stats$SD_SLOWDOWN.STANDBY/sqrt(stats$N)

stats$LOWER_SLOWDOWN.STANDBY <- stats$MEAN_SLOWDOWN.STANDBY - qnorm(0.975)*stats$SD_SLOWDOWN.STANDBY/sqrt(stats$N)

stats2 <- reshape(stats, idvar=c("DENSIDADE","ESCALONADOR","CHECK"), v.names=c("MEAN_SLOWDOWN","SD_SLOWDOWN","UPPER_SLOWDOWN","LOWER_SLOWDOWN"), direction="long", varying=list(c("MEAN_SLOWDOWN.SLEEP","MEAN_SLOWDOWN.STANDBY"), c("SD_SLOWDOWN.SLEEP","SD_SLOWDOWN.STANDBY"),c("UPPER_SLOWDOWN.SLEEP","UPPER_SLOWDOWN.STANDBY"),c("LOWER_SLOWDOWN.SLEEP","LOWER_SLOWDOWN.STANDBY")),times=c("SLEEP","STANDBY"), timevar="GREEN")

print(xYplot(Cbind(MEAN_SLOWDOWN,LOWER_SLOWDOWN,UPPER_SLOWDOWN) ~ MEAN_RUNTIME | ESCALONADOR*CHECK, data=stats2, groups=GREEN, auto.key=TRUE, ylim=c(1,4.5), scale=list(y=list(at=seq(1,4.5,.5)))))

